package com.dtsz.m2.utils;

import android.os.CountDownTimer;
import android.widget.Button;

public class MyCountdownUtils extends CountDownTimer {
    private Button mButton;

    public MyCountdownUtils(Button button, long millisInFuture,
                            long countDownInterval) {
        super(millisInFuture, countDownInterval);

        mButton = button;
    }

    @Override
    public void onFinish() {

        // 获取 验证码按钮可点击
        setButtonEnable();
    }

    @Override
    public void onTick(long millisUntilFinished) {
        // 获取验证码按钮不可点击,倒计时开始
        setButtonUnEnable(millisUntilFinished);

    }

    @SuppressWarnings("deprecation")
    private void setButtonEnable() {

        mButton.setEnabled(true);
        mButton.setText("重新获取");
//        mButton.setBackgroundDrawable(MyApplication.getInstance()
//                .getResources().getDrawable(R.drawable.shape_button_red));

    }

    @SuppressWarnings("deprecation")
    public void setButtonUnEnable(long millisUntilFinished) {
        mButton.setEnabled(false);
        mButton.setText("重新获取" + millisUntilFinished / 1000);
    }

}
